home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Info-Mac 4
/
Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso
/
Development
/
General
/
MM3Tp.sea Folder
/
Made by Marksman
/
Sources
/
mm
/
mmMainMM_Demo.p
< prev
next >
Wrap
Text File
|
1994-01-16
|
23KB
|
648 lines
program mmMainMM_Demo;
{ mmMainMM_Demo }
{
Program name: mmMainMM_Demo
Function: This is the main module for this program.
History: 1/16/94 Original by George Cossey
}
uses
Printing, Folders, Sound,mmCommonMM_Demo,CommonMM_Demo,{}
UInitExitMM_Demo,UeventsMM_Demo,{}
mmPA_My_Alert,
{}
mmD_My_Modal,
{}
mmMD_My_Movable_Moda,
mmMD_My_Modeless,
mmMD_About_Demo,
{}
UMy_basic_window,
UFloating_window,
{}
mmW_My_basic_window,
mmW_Floating_window,
{}
mmMenuMM_Demo;
var
DoIt:Boolean; { Flag saying an event is ready }
code:integer; { Determine event type }
whichWindow:WindowPtr; { See which window for event }
mResult:longint; { Menu list and item selected values }
theMenu,theItem:integer; { Menu list and item selected }
Is_A_Dialog:Boolean; { Flag for modless dialogs }
charCode, itemHit:integer; { For modeless dialogs}
ch:char; { Key pressed in Ascii }
DoTheModelessEvent, CmdDown:Boolean; { For modeless dialogs}
thePeeked:WindowPeek; { For modeless dialogs}
{ ======================================================= }
{ Routine: WNEIsImplemented }
{ Purpose: See if the MultiFinder trap, WaitNextEvent, is available }
function IsWNEIsImplemented:Boolean; { See if WaitNextEvent is available }
const
WNETrapNumber = $A860; { The expected trap number }
kGestaltTrapID = $A1AD; { The expected trap number }
var
theWorld:SysEnvRec; { Environment record }
discardError:OSErr; { Error code returned }
theWNEIsImplemented:Boolean; { Value to return }
result:longint; { Value returned }
begin
Black_ForeColor.red := $0000; Black_ForeColor.green := $0000; Black_ForeColor.blue := $0000; { Get black color }
White_BackColor.red := $FFFF; White_BackColor.green := $FFFF; White_BackColor.blue := $FFFF; { Get white color }
Has.ColorQD := FALSE; { Init to no color QuickDraw }
Has.FPU := FALSE; { Init to no floating point chip }
Has.AppleEvents := FALSE; { Whether AppleEvents are available }
Has.AliasMgr := FALSE; { Whether AliasMgr is available }
Has.EditionMgr := FALSE; { Whether EditionMgr is available }
Has.Gestalt := FALSE; { Whether Gestalt is available }
Has.NewStdFile := FALSE; { Whether NewStdFile is available }
Has.PPCToolbox := FALSE; { Whether PPCToolbox is available }
Has.QuickDraw32Bit := FALSE; { Whether 32Bit QuickDraw is available }
InTheForeground := TRUE; { Init to a foreground app }
discardError := SysEnvirons(1,theWorld); { Check how old this system is }
if (theWorld.machineType < 0) then { Negative means really old }
theWNEIsImplemented := FALSE { Really old ROMs, no WNE possible }
else
begin
theWNEIsImplemented := CheckTrapAvailable(WNETrapNumber,ToolTrap);{ See if trap is there }
Has.ColorQD := theWorld.hasColorQD; { Flag for Color QuickDraw being available }
Has.FPU := theWorld.hasFPU; { Flag for Floating Point Math Chip being available }
Has.Gestalt := CheckTrapAvailable(kGestaltTrapID, ToolTrap);{ Whether Gestalt is available }
if (Has.Gestalt) then { Do if Gestalt is available }
begin
discardError := Gestalt(gestaltAliasMgrAttr,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltAliasMgrPresent)) <> 0)) then
Has.AliasMgr := TRUE;
discardError := Gestalt(gestaltEditionMgrAttr,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltEditionMgrPresent)) <> 0)) then
Has.EditionMgr := TRUE;
discardError := Gestalt(gestaltAppleEventsAttr,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltAppleEventsPresent)) <> 0)) then
Has.AppleEvents := TRUE;
discardError := Gestalt(gestaltPPCToolboxAttr,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltPPCToolboxPresent)) <> 0)) then
Has.PPCToolbox := TRUE;
discardError := Gestalt(gestaltQuickdrawVersion,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestalt32BitQD)) <> 0)) then
Has.QuickDraw32Bit := TRUE;
discardError := Gestalt(gestaltStandardFileAttr,result);
if ((discardError = 0) and (BAND(result, BSL($00000001, gestaltStandardFile58)) <> 0)) then
Has.NewStdFile := TRUE;
end;
end;
IsWNEIsImplemented := theWNEIsImplemented;
end;
{ ======================================================= }
{ Routine: Handle_User_Event }
{ Purpose: Check for user events }
procedure Handle_User_Event; { Check for user events }
var
TheUserEvent:UserEventRec; { The user event }
begin
GetUserEvent(@TheUserEvent); { Check for any user events }
if (TheUserEvent.ID <> UserEvent_None) then { Only do if we have any }
begin
case (TheUserEvent.ID) of { Key off the Event ID }
UserEvent_Open_Window: { Open a Window or Modeless dialog }
begin
case (TheUserEvent.ID2) of { Do the appropiate window }
-1:begin end;
ResA_My_Alert:
PA_My_Alert; { Open this alert }
ResD_My_Modal:
MPD_My_Modal; { Open this modal dialog }
ResD_My_Movable_Moda:
Open_My_Movable_Moda; { Open this modeless dialog }
ResD_My_Modeless:
Open_My_Modeless; { Open this modeless dialog }
ResD_About_Demo:
Open_About_Demo; { Open this modeless dialog }
ResW_My_basic_window:
Open_My_basic_window; { Open this window }
ResW_Floating_window:
Open_Floating_window; { Open this window }
otherwise { Handle others }
begin
end;
end; { End of the switch }
end;
UserEvent_Close_Window: { Close a Window or Modeless dialog }
begin
case (TheUserEvent.ID2) of { Do the appropiate window }
-1:begin end;
ResD_My_Movable_Moda:
Close_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);{ Close this modeless dialog }
ResD_My_Modeless:
Close_My_Modeless(Rec_My_Modeless.theDialog);{ Close this modeless dialog }
ResD_About_Demo:
Close_About_Demo(Rec_About_Demo.theDialog);{ Close this modeless dialog }
ResW_My_basic_window:
Close_My_basic_window(WindowPtr(-1)); { Close this window }
ResW_Floating_window:
Close_Floating_window(WindowPtr(-1)); { Close this window }
otherwise { Handle others }
begin
end;
end; { End of the switch }
end;
otherwise { Not standard, must be program specific }
begin
Handle_UserEvent(@TheUserEvent); { Let program specific handle it }
end;
end; { End of switch }
end;
end;
{ ======================================================= }
{ Routine: DoKeyEvent }
{ Purpose: Handle a key pressed }
procedure DoKeyEvent; { Handle key presses }
var
charCode:integer; { Key code }
ch:char; { Key pressed in Ascii }
mResult:longint; { Menu list and item, if a command key }
theMenu,theItem:integer; { Menu list and item, if command key }
begin
if (HandleKey(myEvent)) then { Allow for special key handling }
begin
charCode := BAND(myEvent.message,charCodeMask); { Get the character }
ch := char(charCode); { Change it to ASCII }
if (BAND(myEvent.modifiers,cmdKey) <> 0) then { See if Command key is down }
begin
U_EnableMenus; { Let us in to enable and disable menus}
mResult := MenuKey(ch); { See if a menu selection }
theMenu := HiWord(mResult); { Get the menu list number }
theItem := LoWord(mResult); { Get the menu item number }
if (theMenu <> 0) then { See if a list was selected }
Handle_My_Menu(theMenu,theItem); { Do the menu selection }
if (((ch = 'x') or (ch = 'X')) and (theInput <> NIL)) then
TECut(theInput) { Handle a Cut in a TE area }
else if (((ch = 'c') or (ch = 'C')) and (theInput <> NIL)) then
TECopy(theInput) { Handle a Copy in a TE area }
else if (((ch = 'v') or (ch = 'V')) and (theInput <> NIL)) then
TEPaste(theInput); { Handle a Paste in a TE area }
end
else if (theInput <> NIL) then
TEKey(ch,theInput); { Place the normal key stroke }
end;
end;
{ ======================================================= }
{ Routine: DoDiskEvent }
{ Purpose: Handle a diskette inserted }
procedure DoDiskEvent; { Handle disk inserted }
var
theError:integer; { Error returned from mount }
begin
if (HandleDisk(myEvent)) then { Allow for special disk inserted handling }
begin
if (HiWord(myEvent.message) <> noErr) then { See if a diskette mount error }
begin
myEvent.where.h := ((screenBits.bounds.right - screenBits.bounds.left) div 2) - (304 div 2);{ Center horz }
myEvent.where.v := ((screenBits.bounds.bottom - screenBits.bounds.top) div 3) - (104 div 2);{ Top 3ed vertically }
InitCursor; { Make sure it has an arrow cursor }
theError := DIBadMount(myEvent.where, myEvent.message);{ Let the OS handle the diskette }
end;
end;
end;
{ ======================================================= }
{ Routine: DoZoom }
{ Purpose: Handle a window zoom }
procedure DoZoom(whichWindow:WindowPtr;code:integer); { Handle a window zoom }
var
OldRect:Rect; { Window rect before the zoom }
myPt:Point; { Point for tracking zoom box }
theRefCon:longint; { Refcon with layer masked off }
begin
if (not(Doing_MovableModal)) then { Select proper window }
begin
if (whichWindow <> NIL) then { See if we have a legal window }
begin
SetPort(whichWindow); { Get ready to draw in this window }
myPt := myEvent.where; { Get mouse position }
GlobalToLocal(myPt); { Make it relative }
OldRect := whichWindow^.portRect; { Save the rect before resizing }
if (TrackBox(whichWindow, myPt, code)) then { Zoom it }
begin
ZoomWindow(whichWindow, code, TRUE); { Resize to result }
EraseRect(whichWindow^.portRect); { Make sure we update the whole window effectively }
InvalRect(whichWindow^.portRect); { Tell ourselves to update, redraw, the window contents }
theRefCon := GetWRefCon(whichWindow); { Get the refcon }
theRefCon := BAND(theRefCon,$00FFFFFF); { Mask the layer out }
case (theRefCon) of { Do the appropiate window }
-1:begin end;
ResW_My_basic_window:
Resized_My_basic_window(OldRect, whichWindow);{ Resized this window }
otherwise { Handle others }
U_DoZoom(OldRect,whichWindow); { Allow user to handle others }
end;
Mk_HiliteWindow(whichWindow); { Hilite it again }
end;
end;
end;
end;
{ ======================================================= }
{ Routine: DoDrag }
{ Purpose: Drag a window around }
procedure DoDrag(whichWindow:WindowPtr);
var
OldRect:Rect; { Window rect before the drag }
tempRect:Rect; { temporary rect }
theRefCon:longint; { Refcon with layer masked off }
begin
if ((not(Doing_MovableModal)) or (Doing_MovableModal and (whichWindow = FrontWindow))) then{ See if OK to drag }
begin
OldRect := whichWindow^.portRect; { Save the rect before resizing }
if (not(Doing_MovableModal)) then { Select proper window }
Mk_HiliteWindow(whichWindow);
SetRect(tempRect, -32000, -32000, 32000, 32000);
Mk_DragWindow(whichWindow,myEvent.where,tempRect);{ Drag the window }
theRefCon := GetWRefCon(whichWindow); { Get the refcon }
theRefCon := BAND(theRefCon,$00FFFFFF); { Mask the layer out }
case (theRefCon) of { Do the appropiate window }
-1:begin end;
ResD_My_Movable_Moda:
Moved_My_Movable_Moda(OldRect,whichWindow); { Moved this modeless dialog }
ResD_My_Modeless:
Moved_My_Modeless(OldRect,whichWindow); { Moved this modeless dialog }
ResD_About_Demo:
Moved_About_Demo(OldRect,whichWindow); { Moved this modeless dialog }
ResW_My_basic_window:
U_MovedMy_basic_window(OldRect,whichWindow);{ Moved this window }
ResW_Floating_window:
U_MovedFloating_window(OldRect,whichWindow);{ Moved this window }
otherwise { allow other buttons, trap for debug }
U_Moved(OldRect,whichWindow); { Allow user to handle others }
end; { end of switch }
end;
end;
{ ======================================================= }
{ Routine: DoGoAway }
{ Purpose: Close a window }
procedure DoGoAway(whichWindow:WindowPtr);
var
theRefCon:longint; { Refcon with layer masked off }
begin
if (not(Doing_MovableModal)) then { Select proper window }
begin
if (TrackGoAway(whichWindow,myEvent.where)) then { See if mouse released in GoAway box }
begin
theRefCon := GetWRefCon(whichWindow); { Get the refcon }
theRefCon := BAND(theRefCon,$00FFFFFF); { Mask the layer out }
case (theRefCon) of { Do the appropiate window }
-1:begin end;
ResD_My_Movable_Moda:
Close_My_Movable_Moda(whichWindow); { Close this modeless dialog }
ResD_My_Modeless:
Close_My_Modeless(whichWindow); { Close this modeless dialog }
ResD_About_Demo:
Close_About_Demo(whichWindow); { Close this modeless dialog }
ResW_My_basic_window:
Close_My_basic_window(whichWindow); { Close this window }
ResW_Floating_window:
Close_Floating_window(whichWindow); { Close this window }
otherwise { allow other buttons, trap for debug }
U_GoAway(whichWindow); { Allow user to handle others }
end; { end of switch }
end;
end;
end;
{ ======================================================= }
{ Routine: DoInContent }
{ Purpose: Pressed in the content area }
procedure DoInContent(whichWindow:WindowPtr;var myEvent:EventRecord);
var
theRefCon:longint; { Refcon with layer masked off }
begin
if (not(Doing_MovableModal)) then { Select proper window }
begin
if (Mk_Is_FrontWindow(whichWindow) = false) then { See if already selected or not, in front if selected }
Mk_HiliteWindow(whichWindow)
else
begin
SetPort(whichWindow); { Get ready to draw in this window }
Mk_HiliteWindow(whichWindow);
theRefCon := GetWRefCon(whichWindow); { Get the refcon }
theRefCon := BAND(theRefCon,$00FFFFFF); { Mask the layer out }
case (theRefCon) of { Do the appropiate window }
-1:begin end;
ResW_My_basic_window:
Do_My_basic_window(myEvent); { Handle this window }
ResW_Floating_window:
Do_Floating_window(myEvent); { Handle this window }
otherwise { allow other buttons, trap for debug }
U_InContent(myEvent,whichWindow); { Allow user to handle others }
end; { end of switch }
end;
end;
end;
{ ======================================================= }
{ Routine: DoUpdate }
{ Purpose: Got an update event }
procedure DoUpdate;
var
whichWindow:WindowPtr; { See which window for event }
theRefCon:longint; { Refcon with layer masked off }
begin
whichWindow := WindowPtr(myEvent.message); { Get the window the update is for }
BeginUpdate(whichWindow); { Set the clipping to the update area }
theRefCon := GetWRefCon(whichWindow); { Get the refcon }
theRefCon := BAND(theRefCon,$00FFFFFF); { Mask the layer out }
case (theRefCon) of { Do the appropiate window }
-1:begin end;
ResW_My_basic_window:
Update_My_basic_window(whichWindow); { Update this window }
ResW_Floating_window:
Update_Floating_window(whichWindow); { Update this window }
otherwise { allow other buttons, trap for debug }
U_Update(whichWindow); { Allow user to handle others }
end; { end of switch }
EndUpdate(whichWindow); { Return to normal clipping area }
end;
{ ======================================================= }
{ ======================================================= }
{ Start of main body }
begin
MoreMasters; { This reserves space for more handles }
MaxApplZone; { Give us room for memory allocation }
InitCursor; { Make an arrow cursor }
doneFlag := FALSE; { Do not exit program yet }
Init_My_Menus; { Initialize menu bar }
theInput := nil; { Init to no text edit selection active }
SleepValue := 40; { Set sleep value }
WNE := IsWNEIsImplemented; { See if WaitNextEvent is available }
UserEventList := nil; { No user events yet }
cursorRgn := NewRgn; { Cursor region for WaitNextEvent }
Printing.hPrint := nil; { Init to no print record yet }
Printing.PrinterIsOpen := false; { We are not printing yet }
U_InitPreferences; { Set default preferences }
InitA_My_Alert; { Initialize Alert, My Alert }
InitD_My_Modal; { Initialize Modal Dialog, My Modal }
Init_My_Movable_Moda; { Initialize Modeless Dialog, My Movable Modal }
Init_My_Modeless; { Initialize Modeless Dialog, My Modeless }
Init_About_Demo; { Initialize Modeless Dialog, About Demo }
Init_My_basic_window; { Initialize Window, My basic window }
Init_Floating_window; { Initialize Window, Floating window }
Mk_ClearLayers; { Init layer array }
Doing_MovableModal := false; { Not currently doing a movable modal }
ApplInitMM_Demo; { Handle extra program initialization }
GetPreferences; { Get preferences }
repeat
ApplLoopMM_Demo; { Hook into the main loop }
Handle_User_Event; { Check for user events }
if (theInput <> NIL) then { See if a TE is active }
TEIdle(theInput); { Blink the cursor if everything is ok }
if (WNE) then { See if do the MultiFinder way }
DoIt := WaitNextEvent(everyEvent,myEvent,SleepValue,cursorRgn) { Wait for an event }
else
begin
SystemTask; { For support of desk accessories }
DoIt := GetNextEvent(everyEvent,myEvent); { See if an event is ready }
end;
ApplEventMM_Demo(DoIt,myEvent); { Let us at the event first }
if (DoIt) then { If event then... }
begin
Is_A_Dialog := IsDialogEvent(myEvent); { See if a modeless dialog event }
if (Is_A_Dialog) then { Handle a dialog event }
begin
if (myEvent.what = updateEvt) then { Handle the update of a Modeless Dialog }
begin
whichWindow := WindowPtr(myEvent.message); { Get the window the update is for }
BeginUpdate(whichWindow); { Set update clipping area }
Update_My_Movable_Moda(whichWindow); { Update Modeless Dialog, My Movable Modal }
Update_My_Modeless(whichWindow); { Update Modeless Dialog, My Modeless }
Update_About_Demo(whichWindow); { Update Modeless Dialog, About Demo }
EndUpdate(whichWindow); { Return to normal clipping area }
end
else
begin
DoTheModelessEvent := TRUE; { Go ahead and do it so far }
if (myEvent.what = keyDown) then { Check the key down, for a command key event }
begin
CmdDown := Boolean(BAND((myEvent.modifiers div cmdKey),1));{ Get the command key state }
charCode := BAND(myEvent.message,charCodeMask); { Get the character }
ch := char(charCode); { Change it to ASCII }
if ((charCode = 13) or (charCode = 3)) then { CR or Enter }
DoTheModelessEvent := TRUE; { Handle the default selection }
if (CmdDown) then { Handle if the command key was down }
begin
U_EnableMenus; { Let us in to enable and disable menus}
mResult := MenuKey(ch); { See if a menu selection }
theMenu := HiWord(mResult); { Get the menu list number }
theItem := LoWord(mResult); { Get the menu item number }
if (theMenu <> 0) then { See if a list was selected }
Handle_My_Menu(theMenu,theItem); { Do the menu selection }
whichWindow := FrontWindow; { Get the front window }
if ((ch = 'x') or (ch = 'X')) then { Handle a CUT }
DlgCut(whichWindow)
else if ((ch = 'c') or (ch = 'C')) then { Handle a COPY }
DlgCopy(whichWindow)
else if ((ch = 'v') or (ch = 'V')) then { Handle a PASTE }
DlgPaste(whichWindow);
DoTheModelessEvent := FALSE;{ We handled the command key }
end;
end;
if (DoTheModelessEvent) then { Do we handle it? }
begin
if ((DialogSelect(myEvent,whichWindow,itemHit)) or (myEvent.what = mouseDown) or (myEvent.what = keyDown)) then { Ck if do it }
begin
Do_My_Movable_Moda(myEvent,whichWindow,itemHit); { Handle the Modeless Dialog, My Movable Modal }
Do_My_Modeless(myEvent,whichWindow,itemHit); { Handle the Modeless Dialog, My Modeless }
Do_About_Demo(myEvent,whichWindow,itemHit); { Handle the Modeless Dialog, About Demo }
end;
end;
end;
end
else
begin
case (myEvent.what) of { Decide type of event }
mouseDown : { Mouse button pressed }
begin
code := FindWindow(myEvent.where,whichWindow);{ Get which window the event happened in }
case (code) of { Decide type of event again }
inMenuBar : { In the menubar }
begin
U_EnableMenus; { Let us in to enable and disable menus}
mResult := MenuSelect(myEvent.where);{ Do menu selection }
theMenu := HiWord(mResult); { Get the menu list number }
theItem := LoWord(mResult); { Get the menu list item number }
Handle_My_Menu(theMenu,theItem); { Handle the menu }
end;
inDrag : { In window drag area }
DoDrag(whichWindow);{ Go drag the window }
inZoomIn,inZoomOut : { In window zoom area }
DoZoom(whichWindow,code);{ Go zoom the window }
inGoAway : { In window goaway area }
DoGoAway(whichWindow);{ Handle the goaway button }
inContent : { In window contents }
DoInContent(whichWindow,myEvent);{ Handle the hit inside a window }
inSysWindow : { See if a DA selection }
SystemClick(myEvent,whichWindow);{ Let other programs in }
otherwise { Handle others }
begin
end; { End of otherwise }
end; { End of code case }
end; { End of MouseDown }
keyDown,autoKey: { and auto repeats }
DoKeyEvent; { Get the key and handle it }
updateEvt : { Update event for a window }
DoUpdate; { Handle the update }
diskEvt : { Disk inserted event }
DoDiskEvent; { Handle a disk event }
activateEvt : { Window activated event }
DoActivate; { Handle the activation }
osEvt: { OS event }
DoOSEvent(myEvent); { Handle the activation }
otherwise { Used for debugging, to see what other events are coming in }
begin
end; { End of otherwise }
end; { End of case }
end;
end
else
begin
whichWindow := FrontWindow; { Get the current front window }
if (whichWindow <> NIL) then { See if we have a window }
begin
thePeeked := WindowPeek(whichWindow); { Peek inside, look for dialog }
if (thePeeked^.windowKind = dialogKind) then { DialogSelect will crash if no dialogs }
begin
if (DialogSelect(myEvent,whichWindow,itemHit)) then { Blink cursor in modeless TEs }
begin
end;
end;
end;
end;
until ( doneFlag ); { End of the event loop }
ApplExitMM_Demo; { Handle extra program termination code }
Close_My_Movable_Moda(Rec_My_Movable_Moda.theDialog);{ Close this modeless dialog }
Close_My_Modeless(Rec_My_Modeless.theDialog);{ Close this modeless dialog }
Close_About_Demo(Rec_About_Demo.theDialog);{ Close this modeless dialog }
Close_My_basic_window(WindowPtr(-1)); { Close this window }
Close_Floating_window(WindowPtr(-1)); { Close this window }
SetPreferences; { Set new preferences }
end.